package com.ruoyi.mail.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaMallProductType;
import com.ruoyi.system.service.IJiajiaMallProductTypeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城产品大类Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/mall/type")
public class JiajiaMallProductTypeController extends BaseController
{
    private String prefix = "mall/type";

    @Autowired
    private IJiajiaMallProductTypeService jiajiaMallProductTypeService;

    @RequiresPermissions("system:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询商城产品大类列表
     */
    @RequiresPermissions("system:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaMallProductType jiajiaMallProductType)
    {
        startPage();
        List<JiajiaMallProductType> list = jiajiaMallProductTypeService.selectJiajiaMallProductTypeList(jiajiaMallProductType);
        return getDataTable(list);
    }

    /**
     * 导出商城产品大类列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "商城产品大类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaMallProductType jiajiaMallProductType)
    {
        List<JiajiaMallProductType> list = jiajiaMallProductTypeService.selectJiajiaMallProductTypeList(jiajiaMallProductType);
        ExcelUtil<JiajiaMallProductType> util = new ExcelUtil<JiajiaMallProductType>(JiajiaMallProductType.class);
        return util.exportExcel(list, "商城产品大类数据");
    }

    /**
     * 新增商城产品大类
     */
    @GetMapping("/add")
    public String add()
    {

        return prefix + "/add";
    }






    /**
     * 新增保存商城产品大类
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "商城产品大类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaMallProductType jiajiaMallProductType)
    {
        return toAjax(jiajiaMallProductTypeService.insertJiajiaMallProductType(jiajiaMallProductType));
    }

    /**
     * 修改商城产品大类
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaMallProductType jiajiaMallProductType = jiajiaMallProductTypeService.selectJiajiaMallProductTypeById(id);
        mmap.put("jiajiaMallProductType", jiajiaMallProductType);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城产品大类
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "商城产品大类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaMallProductType jiajiaMallProductType)
    {
        return toAjax(jiajiaMallProductTypeService.updateJiajiaMallProductType(jiajiaMallProductType));
    }

    /**
     * 删除商城产品大类
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "商城产品大类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaMallProductTypeService.deleteJiajiaMallProductTypeByIds(ids));
    }


    @RequiresPermissions("system:type:list")
    @GetMapping("/detail/{id}")
    public String detail(@PathVariable("id") Long id, ModelMap mmap)
    {
       mmap.put("type", jiajiaMallProductTypeService.selectJiajiaMallProductTypeById(id));
        mmap.put("typeList", jiajiaMallProductTypeService.selectJiajiaMallProductTypeList(new JiajiaMallProductType()));
        return "mall/level/level";
    }


    @GetMapping("/select")
    @ResponseBody
    public List<JiajiaMallProductType> select(){
        List<JiajiaMallProductType> list = jiajiaMallProductTypeService.selectJiajiaMallProductTypeList(new JiajiaMallProductType());
        return  list;
    }

}
